package com.coze.lg.cozeagent.controller.oldtest;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册WebSocket处理器，指定访问路径，并允许跨域
        registry.addHandler(new socketWebSocketSpringBoot(), "/ws")
                .setAllowedOrigins("*");

        // 为不支持WebSocket的浏览器提供SockJS备用方案
        registry.addHandler(new socketWebSocketSpringBoot(), "/sockjs/ws")
                .setAllowedOrigins("*")
                .withSockJS();
    }
}
